﻿using System;
using System.Collections.Generic;
using System.Text;
using Li.Repository.IRepository;
using EFCore.Entity;
using System.Linq;
using Microsoft.EntityFrameworkCore;
using EFCore;
using CommonTool;

namespace Li.Repository.Repository
{
    public class BaseRepository<T> : EFRepository, IBaseRepository<T> where T : class
    {
        protected MyContext _db;
        public BaseRepository(MyContext myContext) : base(myContext)
        {
            _db = myContext;
        }

        public void Add(T entity)
        {
            _db.Set<T>().Add(entity);
        }

        public int Commit()
        {
            return _db.SaveChanges();
        }

        public void Delete(T entity)
        {
            _db.Set<T>().Remove(entity);
        }

        public IQueryable<T> GetAll()
        {
            return _db.Set<T>();
        }

        public void RemoveRange(List<T> all)
        {
            _db.Set<T>().RemoveRange(all);
        }
    }
}
